package com.weike.foodsafey;

import com.weike.foodsafe.entity.GoodsEntity;
import com.weike.foodsafe.entity.InventoryEntity;
import com.weike.foodsafe.service.GoodsService;
import com.weike.foodsafe.service.InventoryService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @ClassName: addData
 * @Author: YuanDing
 * @Date: 2024/4/27 17:27
 * @Description:
 */

@SpringBootTest
public class addData {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private InventoryService inventoryService;

    @Test
    public void test1(){
        List<GoodsEntity> list = goodsService.list();

        List<InventoryEntity> collect = list.stream().map(goodsEntity -> {
            InventoryEntity inventoryEntity = new InventoryEntity();
            inventoryEntity.setInventoryId(UUID.randomUUID().toString());
            inventoryEntity.setInventoryName(goodsEntity.getGoodsname());
            inventoryEntity.setInventoryNumber(0);
            inventoryEntity.setPurchaseDate(new Date());
            inventoryEntity.setInventoryGoodsId(goodsEntity.getGoodsid());
            inventoryEntity.setDistributionId(goodsEntity.getDistributionid());
            inventoryEntity.setGoodsUnit(goodsEntity.getGoodsunit());
            
            return inventoryEntity;
        }).collect(Collectors.toList());

        inventoryService.saveBatch(collect);
    }

}
